package com.weavernorth.promotionPlan.service;

import com.google.gson.JsonObject;
import com.weavernorth.promotionPlan.pojo.*;
import com.weavernorth.util.Logger4jUtil;
import com.weavernorth.util.MyCommonUtils;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.log4j.Logger;
import weaver.conn.RecordSet;
import weaver.conn.RecordSetTrans;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.workflow.webservices.*;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 王文彬
 * @date 2020/10/26 18:04
 * @description 描述：促销方案V8取数并自动创建流程
 */
public class promPlanService {
    private Logger log = Logger4jUtil.getLoggerByName("/action/api/promotionPlanApi/");

    public JSONObject createWorkFlow(JSONObject jsonObject) {
        BaseBean bb = new BaseBean();
        //获取创建人id
        //String strCreator = bb.getPropValue("csfaProps", "creator");
        //log.info("创建流程人员：" + strCreator);
        String table_Main = bb.getPropValue("csfaProps", "mainTable");
        Boolean isExists_cxfabh=true;
        log.info("OA表单主表：" + table_Main);
        //region[创建接收json数据的map]
        JSONObject jsonResult = new JSONObject();
        Map<String, Class<?>> classMap = new HashMap<String, Class<?>>();
        classMap.put("shop", shopEntity.class);
        classMap.put("cxb", cxbEntity.class);
        classMap.put("zhcx", zhcxEntity.class);
        classMap.put("cxsp", cxspEntity.class);
        classMap.put("cyry", cyryEntity.class);
        classMap.put("zp", zpEntity.class);
        classMap.put("szzk", szzkEntity.class);
        //endregion
        try {
            mainVo dataVo = (mainVo) net.sf.json.JSONObject.toBean(jsonObject, mainVo.class, classMap);
            List<shopEntity> shop_list = dataVo.getShop();//参与店铺明细表
            List<cxbEntity> cxb_list = dataVo.getCxb();//商品/促销包明细表
            List<zhcxEntity> zhcx_list = dataVo.getZhcx();//组合促销明细表
            List<cyryEntity> cyry_list = dataVo.getCyry();//参与人员明细表
            List<zpEntity> zp_list = dataVo.getZp();//赠品明细表
            List<szzkEntity> szzk_list = dataVo.getSzzk();//设参与人群赠品信息置折扣明细表
            String strCxbh=dataVo.getCxfabh();
            log.info("促销方案编号：" + dataVo.getCxfabh());
            RecordSet rs=new RecordSet();
            String strQuery="select b.currentnodetype status from "+table_Main+" a,workflow_requestbase b where a.requestid=b.requestid and  a.cxfabh='"+strCxbh+"'";
            log.info("查询促销方案编号下的数据："+strQuery);
            rs.execute(strQuery);
            boolean isExists=false;
            while (rs.next()){
                String status = rs.getString("status");
                log.info("流程状态status="+status);
                if("3".equals(status)){
                    isExists=false;
                }else{
                    isExists=true;
                }
            }
            log.info("流程编号："+dataVo.getLcbh());
            Boolean lcbhIsExists= isExists_lcbh(dataVo.getLcbh());
            log.info("台账表中bpm编号是否存在："+lcbhIsExists);
            if(!lcbhIsExists){
                jsonResult.put("status", "F");
                jsonResult.put("message", "BPM流程编号"+dataVo.getLcbh()+"无效或已被使用,请检查是否填写正确！");
            }else {
                //region[先判断oa系统中是否有此单据,没有则创建新流程，有则更新数据]
                if (isExists) {
                    log.info("更新流程数据=======>");
                    //region[更新流程主表]
                    String strSqls = "select a.id,a.requestid from " + table_Main + " a,workflow_requestbase b where a.requestid=b.requestid and b.currentnodetype !=3 and a.cxfabh='" + strCxbh + "'";
                    log.info("根据促销方案编号获取相关信息：" + strSqls);
                    String strMainid = "";
                    String strRequestid = "";
                    int userid = Integer.parseInt(MyCommonUtils.getUseridByCode(dataVo.getTbr()));
                    RecordSet rs_getMainid = new RecordSet();
                    rs_getMainid.execute(strSqls);
                    while (rs_getMainid.next()) {
                        strMainid = rs_getMainid.getString("id");
                        log.info("主表主键：" + strMainid);
                        strRequestid = rs_getMainid.getString("requestid");
                        log.info("requestId：" + strRequestid);
                    }
                    Boolean result_m = updateTable_main(table_Main, strCxbh, dataVo, strMainid);
                    Boolean result_dt1 = updateTable_dt1(table_Main, strMainid, strCxbh, shop_list);//更新参与店铺明细表
                    Boolean result_dt2 = updateTable_dt2(table_Main, strMainid, strCxbh, cxb_list);//更新商品/促销包明细表
                    Boolean result_dt3 = updateTable_dt3(table_Main, strMainid, strCxbh, zhcx_list);//更新组合促销明细表
                    Boolean result_dt4 = updateTable_dt4(table_Main, strMainid, strCxbh, cyry_list);//更新参与人员明细表
                    Boolean result_dt5 = updateTable_dt5(table_Main, strMainid, strCxbh, zp_list);//更新赠品明细表
                    Boolean result_dt6 = updateTable_dt6(table_Main, strMainid, strCxbh, szzk_list);//更新设参与人群赠品信息置折扣明细表
                    if (result_m && result_dt1 && result_dt2 && result_dt3 && result_dt4 && result_dt5 && result_dt6) {
                        jsonResult.put("status", "S");
                        jsonResult.put("message", "数据更新成功！");
                    } else {
                        jsonResult.put("status", "F");
                        jsonResult.put("message", "数据更新失败,请联系OA系统管理员");
                    }
                    WorkflowServiceImpl wfsi = new WorkflowServiceImpl();
                    WorkflowRequestInfo wrInfo = wfsi.getWorkflowRequest(Integer.parseInt(strRequestid), userid, Integer.parseInt(strRequestid));
                    wrInfo.setIsnextflow("1");
                    String response = wfsi.submitWorkflowRequest(wrInfo, Integer.parseInt(strRequestid), userid, "submit", dataVo.getTjbz());
                    log.info("退回后重新提交自动流转到下一节点：" + response);
                    //endregion
                    //region[更新流程明细表]
                    //endregion
                } else {
                    //region[创建流程]
                    log.info("创建流程数据=======>");
                    //创建流程的主表
                    WorkflowRequestTableField[] wrMain = new WorkflowRequestTableField[43];

                    String strUserid = MyCommonUtils.getUseridByCode(dataVo.getTbr());
                    log.info("填报人工号：" + dataVo.getTbr() + "填报人id:" + strUserid);
                    if ("".equals(strUserid)) {
                        jsonResult.put("status", "F");
                        jsonResult.put("message", "系统无对应的填报人,请填写正确的工号！");
                    } else {
                        //region[填装主表]

                        //region[填报人信息]
                        //填报人
                        wrMain[0] = new WorkflowRequestTableField();
                        wrMain[0].setFieldName("tbr");
                        wrMain[0].setFieldValue(strUserid);
                        wrMain[0].setView(true);
                        wrMain[0].setEdit(true);
                        wrMain[0].setFieldOrder(0);
                        wrMain[0].setMand(false);
                        //填报时间
                        String strTbDate = dataVo.getTbsj();
                        if (strTbDate.length() > 10) {
                            strTbDate = strTbDate.substring(0, 10);
                        }
                        log.info("填报时间：" + dataVo.getTbsj());
                        wrMain[1] = new WorkflowRequestTableField();
                        wrMain[1].setFieldName("tbsj");
                        wrMain[1].setFieldValue(strTbDate);
                        wrMain[1].setView(true);
                        wrMain[1].setEdit(true);
                        wrMain[1].setFieldOrder(0);
                        wrMain[1].setMand(false);

                        //填报部门
                        String strDep = MyCommonUtils.getDepByCode(dataVo.getTbr());
                        log.info("填报部门：");
                        wrMain[2] = new WorkflowRequestTableField();
                        wrMain[2].setFieldName("tbbm");
                        wrMain[2].setFieldValue(strDep);
                        wrMain[2].setView(true);
                        wrMain[2].setEdit(true);
                        wrMain[2].setFieldOrder(0);
                        wrMain[2].setMand(false);

                        //联系电话
                        log.info("联系电话：" + dataVo.getLxdh());
                        wrMain[3] = new WorkflowRequestTableField();
                        wrMain[3].setFieldName("lxdh");
                        wrMain[3].setFieldValue(dataVo.getLxdh());
                        wrMain[3].setView(true);
                        wrMain[3].setEdit(true);
                        wrMain[3].setFieldOrder(0);
                        wrMain[3].setMand(false);
                        //endregion
                        //region[促销方案信息]
                        //促销方案编号
                        log.info("促销方案编号：" + dataVo.getCxfabh());
                        wrMain[4] = new WorkflowRequestTableField();
                        wrMain[4].setFieldName("cxfabh");
                        wrMain[4].setFieldValue(dataVo.getCxfabh());
                        wrMain[4].setView(true);
                        wrMain[4].setEdit(true);
                        wrMain[4].setFieldOrder(0);
                        wrMain[4].setMand(false);

                        log.info("促销方案说明：" + dataVo.getCxfasm());
                        wrMain[5] = new WorkflowRequestTableField();
                        wrMain[5].setFieldName("cxfasm");
                        wrMain[5].setFieldValue(dataVo.getCxfasm());
                        wrMain[5].setView(true);
                        wrMain[5].setEdit(true);
                        wrMain[5].setFieldOrder(0);
                        wrMain[5].setMand(false);

                        log.info("促销方案详细说明：" + dataVo.getCxfaxxsm());
                        wrMain[6] = new WorkflowRequestTableField();
                        wrMain[6].setFieldName("cxfaxxsm");
                        wrMain[6].setFieldValue(dataVo.getCxfaxxsm());
                        wrMain[6].setView(true);
                        wrMain[6].setEdit(true);
                        wrMain[6].setFieldOrder(0);
                        wrMain[6].setMand(false);

                        log.info("促销原因：" + dataVo.getCxyy());
                        wrMain[7] = new WorkflowRequestTableField();
                        wrMain[7].setFieldName("cxyy");
                        wrMain[7].setFieldValue(dataVo.getCxyy());
                        wrMain[7].setView(true);
                        wrMain[7].setEdit(true);
                        wrMain[7].setFieldOrder(0);
                        wrMain[7].setMand(false);

                        log.info("优先顺序：" + dataVo.getYxsx());
                        wrMain[8] = new WorkflowRequestTableField();
                        wrMain[8].setFieldName("yxsx");
                        wrMain[8].setFieldValue(dataVo.getYxsx());
                        wrMain[8].setView(true);
                        wrMain[8].setEdit(true);
                        wrMain[8].setFieldOrder(0);
                        wrMain[8].setMand(false);

                        log.info("促销理论折扣：" + dataVo.getCxllzk());
                        wrMain[9] = new WorkflowRequestTableField();
                        wrMain[9].setFieldName("cxllzk");
                        wrMain[9].setFieldValue(dataVo.getCxllzk());
                        wrMain[9].setView(true);
                        wrMain[9].setEdit(true);
                        wrMain[9].setFieldOrder(0);
                        wrMain[9].setMand(false);

                        String strStartDate = dataVo.getCxqsrq();
                        if (strStartDate.length() > 10) {
                            strStartDate = strStartDate.substring(0, 10);
                        }
                        log.info("促销起始日期：" + dataVo.getCxqsrq());
                        wrMain[10] = new WorkflowRequestTableField();
                        wrMain[10].setFieldName("cxqsrq");
                        wrMain[10].setFieldValue(strStartDate);
                        wrMain[10].setView(true);
                        wrMain[10].setEdit(true);
                        wrMain[10].setFieldOrder(0);
                        wrMain[10].setMand(false);

                        String strEndDate = dataVo.getCxjsrq();
                        if (strEndDate.length() > 10) {
                            strEndDate = strEndDate.substring(0, 10);
                        }
                        log.info("促销结束日期：" + dataVo.getCxjsrq());
                        wrMain[11] = new WorkflowRequestTableField();
                        wrMain[11].setFieldName("cxjsrq");
                        wrMain[11].setFieldValue(strEndDate);
                        wrMain[11].setView(true);
                        wrMain[11].setEdit(true);
                        wrMain[11].setFieldOrder(0);
                        wrMain[11].setMand(false);

                        log.info("返券金额(元)：" + dataVo.getFqjey());
                        wrMain[12] = new WorkflowRequestTableField();
                        wrMain[12].setFieldName("fqjey");
                        wrMain[12].setFieldValue(dataVo.getFqjey());
                        wrMain[12].setView(true);
                        wrMain[12].setEdit(true);
                        wrMain[12].setFieldOrder(0);
                        wrMain[12].setMand(false);

                        log.info("满减金额(元)：" + dataVo.getMjjey());
                        wrMain[13] = new WorkflowRequestTableField();
                        wrMain[13].setFieldName("mjjey");
                        wrMain[13].setFieldValue(dataVo.getMjjey());
                        wrMain[13].setView(true);
                        wrMain[13].setEdit(true);
                        wrMain[13].setFieldOrder(0);
                        wrMain[13].setMand(false);

                        log.info("审核批次：" + dataVo.getShpc());
                        wrMain[14] = new WorkflowRequestTableField();
                        wrMain[14].setFieldName("shpc");
                        wrMain[14].setFieldValue("0");
                        wrMain[14].setView(true);
                        wrMain[14].setEdit(true);
                        wrMain[14].setFieldOrder(0);
                        wrMain[14].setMand(false);

                        log.info("提交备注：" + dataVo.getTjbz());
                        wrMain[15] = new WorkflowRequestTableField();
                        wrMain[15].setFieldName("tjbz");
                        wrMain[15].setFieldValue(dataVo.getTjbz());
                        wrMain[15].setView(true);
                        wrMain[15].setEdit(true);
                        wrMain[15].setFieldOrder(0);
                        wrMain[15].setMand(false);

                        log.info("审批备注：" + dataVo.getSpbz());
                        wrMain[16] = new WorkflowRequestTableField();
                        wrMain[16].setFieldName("spbz");
                        wrMain[16].setFieldValue(dataVo.getSpbz());
                        wrMain[16].setView(true);
                        wrMain[16].setEdit(true);
                        wrMain[16].setFieldOrder(0);
                        wrMain[16].setMand(false);

                        log.info("活动类型：" + dataVo.getHdlx());
                        wrMain[17] = new WorkflowRequestTableField();
                        wrMain[17].setFieldName("hdlx");
                        wrMain[17].setFieldValue(dataVo.getHdlx());
                        wrMain[17].setView(true);
                        wrMain[17].setEdit(true);
                        wrMain[17].setFieldOrder(0);
                        wrMain[17].setMand(false);

                        log.info("Y折扣条件：" + dataVo.getYzktj());
                        wrMain[18] = new WorkflowRequestTableField();
                        wrMain[18].setFieldName("yzktj");
                        wrMain[18].setFieldValue(dataVo.getYzktj());
                        wrMain[18].setView(true);
                        wrMain[18].setEdit(true);
                        wrMain[18].setFieldOrder(0);
                        wrMain[18].setMand(false);

                        log.info("N数量条件：" + dataVo.getNsltj());
                        wrMain[19] = new WorkflowRequestTableField();
                        wrMain[19].setFieldName("nsltj");
                        wrMain[19].setFieldValue(dataVo.getNsltj());
                        wrMain[19].setView(true);
                        wrMain[19].setEdit(true);
                        wrMain[19].setFieldOrder(0);
                        wrMain[19].setMand(false);

                        log.info("X金额条件：" + dataVo.getXjetj());
                        wrMain[20] = new WorkflowRequestTableField();
                        wrMain[20].setFieldName("xjetj");
                        wrMain[20].setFieldValue(dataVo.getXjetj());
                        wrMain[20].setView(true);
                        wrMain[20].setEdit(true);
                        wrMain[20].setFieldOrder(0);
                        wrMain[20].setMand(false);

                        log.info("排序条件：" + dataVo.getPxtj());
                        wrMain[21] = new WorkflowRequestTableField();
                        wrMain[21].setFieldName("pxtj");
                        wrMain[21].setFieldValue(dataVo.getPxtj());
                        wrMain[21].setView(true);
                        wrMain[21].setEdit(true);
                        wrMain[21].setFieldOrder(0);
                        wrMain[21].setMand(false);
                        //endregion
                        //region[标志信息]
                        log.info("参与整单标志：" + dataVo.getCyzdbz());
                        wrMain[22] = new WorkflowRequestTableField();
                        wrMain[22].setFieldName("cyzdbz");
                        wrMain[22].setFieldValue("Y".equals(dataVo.getCyzdbz()) ? "1" : "0");
                        wrMain[22].setView(true);
                        wrMain[22].setEdit(true);
                        wrMain[22].setFieldOrder(0);
                        wrMain[22].setMand(false);

                        log.info("强制参与整单：" + dataVo.getQzcyzd());
                        wrMain[23] = new WorkflowRequestTableField();
                        wrMain[23].setFieldName("qzcyzd");
                        wrMain[23].setFieldValue("Y".equals(dataVo.getQzcyzd()) ? "1" : "0");
                        wrMain[23].setView(true);
                        wrMain[23].setEdit(true);
                        wrMain[23].setFieldOrder(0);
                        wrMain[23].setMand(false);
                        log.info("过期标志：" + dataVo.getGqbz());
                        wrMain[24] = new WorkflowRequestTableField();
                        wrMain[24].setFieldName("gqbz");
                        wrMain[24].setFieldValue("Y".equals(dataVo.getGqbz()) ? "1" : "0");
                        wrMain[24].setView(true);
                        wrMain[24].setEdit(true);
                        wrMain[24].setFieldOrder(0);
                        wrMain[24].setMand(false);
                        log.info("是否折后减：" + dataVo.getSfzhj());
                        wrMain[25] = new WorkflowRequestTableField();
                        wrMain[25].setFieldName("sfzhj");
                        wrMain[25].setFieldValue("Y".equals(dataVo.getSfzhj()) ? "1" : "0");
                        wrMain[25].setView(true);
                        wrMain[25].setEdit(true);
                        wrMain[25].setFieldOrder(0);
                        wrMain[25].setMand(false);
                        log.info("整单促销是否强制送赠品：" + dataVo.getZdcxsfqzszp());
                        wrMain[26] = new WorkflowRequestTableField();
                        wrMain[26].setFieldName("zdcxsfqzszp");
                        wrMain[26].setFieldValue("Y".equals(dataVo.getZdcxsfqzszp()) ? "1" : "0");
                        wrMain[26].setView(true);
                        wrMain[26].setEdit(true);
                        wrMain[26].setFieldOrder(0);
                        wrMain[26].setMand(false);
                        log.info("单件满减：" + dataVo.getDjmj());
                        wrMain[27] = new WorkflowRequestTableField();
                        wrMain[27].setFieldName("djmj");
                        wrMain[27].setFieldValue("Y".equals(dataVo.getDjmj()) ? "1" : "0");
                        wrMain[27].setView(true);
                        wrMain[27].setEdit(true);
                        wrMain[27].setFieldOrder(0);
                        wrMain[27].setMand(false);
                        log.info("促销原因编码：" + dataVo.getCxyyCode());
                        wrMain[28] = new WorkflowRequestTableField();
                        wrMain[28].setFieldName("cxyycode");
                        wrMain[28].setFieldValue(dataVo.getCxyyCode());
                        wrMain[28].setView(true);
                        wrMain[28].setEdit(true);
                        wrMain[28].setFieldOrder(0);
                        wrMain[28].setMand(false);
                        log.info("审核批次编码：" + dataVo.getShpc());
                        wrMain[29] = new WorkflowRequestTableField();
                        wrMain[29].setFieldName("shpccode");
                        wrMain[29].setFieldValue("未提交");
                        wrMain[29].setView(true);
                        wrMain[29].setEdit(true);
                        wrMain[29].setFieldOrder(0);
                        wrMain[29].setMand(false);
                        log.info("活动类型编码：" + dataVo.getHdlxCode());
                        wrMain[30] = new WorkflowRequestTableField();
                        wrMain[30].setFieldName("hdlxcode");
                        wrMain[30].setFieldValue(dataVo.getCxyyCode());
                        wrMain[30].setView(true);
                        wrMain[30].setEdit(true);
                        wrMain[30].setFieldOrder(0);
                        wrMain[30].setMand(false);
                        //log.info("排序条件编码："+dataVo.getPxtjCode());
                        wrMain[31] = new WorkflowRequestTableField();
                        wrMain[31].setFieldName("pxtjcode");
                        wrMain[31].setFieldValue("");
                        wrMain[31].setView(true);
                        wrMain[31].setEdit(true);
                        wrMain[31].setFieldOrder(0);
                        wrMain[31].setMand(false);

                        log.info("备注：" + dataVo.getBz());
                        wrMain[32] = new WorkflowRequestTableField();
                        wrMain[32].setFieldName("bz");
                        wrMain[32].setFieldValue(dataVo.getBz());
                        wrMain[32].setView(true);
                        wrMain[32].setEdit(true);
                        wrMain[32].setFieldOrder(0);
                        wrMain[32].setMand(false);

                        log.info("工号：" + dataVo.getTbr());
                        wrMain[33] = new WorkflowRequestTableField();
                        wrMain[33].setFieldName("gh");
                        wrMain[33].setFieldValue(dataVo.getTbr());
                        wrMain[33].setView(true);
                        wrMain[33].setEdit(true);
                        wrMain[33].setFieldOrder(0);
                        wrMain[33].setMand(false);

                        log.info("bpmsqbh：" + dataVo.getLcbh());
                        wrMain[34] = new WorkflowRequestTableField();
                        wrMain[34].setFieldName("bpmsqbh");
                        wrMain[34].setFieldValue(dataVo.getLcbh());
                        wrMain[34].setView(true);
                        wrMain[34].setEdit(true);
                        wrMain[34].setFieldOrder(0);
                        wrMain[34].setMand(false);

                        String strCsjl = "";
                        if (!"".equals(dataVo.getLcbh())) {
                            strCsjl = getCsjl(dataVo.getLcbh());
                        }
                        //城市经理
                        log.info("城市经理：" + strCsjl);
                        wrMain[35] = new WorkflowRequestTableField();
                        wrMain[35].setFieldName("csjl");
                        wrMain[35].setFieldValue(strCsjl);
                        wrMain[35].setView(true);
                        wrMain[35].setEdit(true);
                        wrMain[35].setFieldOrder(0);
                        wrMain[35].setMand(false);

                        //原值销售
                        log.info("原值销售：" + dataVo.getYzxs());
                        wrMain[36] = new WorkflowRequestTableField();
                        wrMain[36].setFieldName("yzxs");
                        wrMain[36].setFieldValue("Y".equals(dataVo.getYzxs()) ? "1" : "0");
                        wrMain[36].setView(true);
                        wrMain[36].setEdit(true);
                        wrMain[36].setFieldOrder(0);
                        wrMain[36].setMand(false);

                        //是否整体有折扣
                        log.info("是否整体有折扣：" + dataVo.getSfztyzk());
                        wrMain[37] = new WorkflowRequestTableField();
                        wrMain[37].setFieldName("sfztyzk");
                        wrMain[37].setFieldValue(dataVo.getSfztyzk());
                        wrMain[37].setView(true);
                        wrMain[37].setEdit(true);
                        wrMain[37].setFieldOrder(0);
                        wrMain[37].setMand(false);

                        //品牌
                        String strPp = getPP(dataVo.getLcbh());
                        log.info("品牌：" + strPp);
                        wrMain[38] = new WorkflowRequestTableField();
                        wrMain[38].setFieldName("pp");
                        wrMain[38].setFieldValue(strPp);
                        wrMain[38].setView(true);
                        wrMain[38].setEdit(true);
                        wrMain[38].setFieldOrder(0);
                        wrMain[38].setMand(false);
                        //大区经理
                        String strDqjl = getInfos(dataVo.getLcbh(), "dqjl");
                        log.info("大区经理：" + strDqjl);
                        wrMain[39] = new WorkflowRequestTableField();
                        wrMain[39].setFieldName("dqjl");
                        wrMain[39].setFieldValue(strDqjl);
                        wrMain[39].setView(true);
                        wrMain[39].setEdit(true);
                        wrMain[39].setFieldOrder(0);
                        wrMain[39].setMand(false);
                        //货品人员
                        String strHpry = getInfos(dataVo.getLcbh(), "hpry");
                        log.info("货品人员：" + strHpry);
                        wrMain[40] = new WorkflowRequestTableField();
                        wrMain[40].setFieldName("hpry");
                        wrMain[40].setFieldValue(strHpry);
                        wrMain[40].setView(true);
                        wrMain[40].setEdit(true);
                        wrMain[40].setFieldOrder(0);
                        wrMain[40].setMand(false);
                        //财务稽核
                        String strCwjh = getInfos(dataVo.getLcbh(), "cwjh");
                        log.info("财务稽核：" + strCwjh);
                        wrMain[41] = new WorkflowRequestTableField();
                        wrMain[41].setFieldName("cwjh");
                        wrMain[41].setFieldValue(strCwjh);
                        wrMain[41].setView(true);
                        wrMain[41].setEdit(true);
                        wrMain[41].setFieldOrder(0);
                        wrMain[41].setMand(false);
                        //促销方案申请流程请求id
                        String strQqid = getInfos(dataVo.getLcbh(), "qqid");
                        log.info("请求id：" + strQqid);
                        wrMain[42] = new WorkflowRequestTableField();
                        wrMain[42].setFieldName("cxfasqlc");
                        wrMain[42].setFieldValue(strQqid);
                        wrMain[42].setView(true);
                        wrMain[42].setEdit(true);
                        wrMain[42].setFieldOrder(0);
                        wrMain[42].setMand(false);
                        //endregion
                        //获取workflowid
                        String workflowid = bb.getPropValue("csfaProps", "flowid");
                        log.info("workflowid的值：" + workflowid);
                        //配置流程基本信息:workflowId
                        WorkflowBaseInfo wbi = new WorkflowBaseInfo();
                        wbi.setWorkflowId(workflowid);
                        //填装主表相关字段对象
                        WorkflowRequestTableRecord[] wrtri_m = new WorkflowRequestTableRecord[1];
                        wrtri_m[0] = new WorkflowRequestTableRecord();
                        wrtri_m[0].setWorkflowRequestTableFields(wrMain);
                        //创建流程主表信息对象
                        WorkflowMainTableInfo wmi_m = new WorkflowMainTableInfo();
                        wmi_m.setRequestRecords(wrtri_m);

                        WorkflowRequestInfo wrInfo = new WorkflowRequestInfo();
                        wrInfo.setRequestLevel("0");//紧急程度
                        wrInfo.setRequestName("【品牌】促销方案审批流程");//流程的名称
                        //0:停留在提交节点;1:自动流转到下一节点
                        wrInfo.setIsnextflow("1");
                        //主表数据
                        wrInfo.setWorkflowMainTableInfo(wmi_m);
                        wrInfo.setWorkflowBaseInfo(wbi);

                        //endregion

                        //region[填装明细表]

                        WorkflowDetailTableInfo[] wdti = new WorkflowDetailTableInfo[6];
                        //region[明细表构造-参与店面信息]
                        if (shop_list.size() > 0) {
                            wrtri_m = getDetail_1(shop_list);
                            wdti[0] = new WorkflowDetailTableInfo();
                            wdti[0].setWorkflowRequestTableRecords(wrtri_m);
                        }

                        //endregion
                        //region[明细表构造-参与商品/促销包信息]
                        if (cxb_list.size() > 0) {
                            wrtri_m = getDetail_2(cxb_list);
                            wdti[1] = new WorkflowDetailTableInfo();
                            wdti[1].setWorkflowRequestTableRecords(wrtri_m);
                        }

                        //endregion
                        //region[明细表构造-参与商品方案/组合促销]
                        if (zhcx_list.size() > 0) {
                            wrtri_m = getDetail_3(zhcx_list);
                            log.info("明细表4的记录长度：" + wrtri_m.length);
                            wdti[2] = new WorkflowDetailTableInfo();
                            wdti[2].setWorkflowRequestTableRecords(wrtri_m);
                        }

                        //endregion
                        //region[明细表构造-参与人群信息]
                        if (cyry_list.size() > 0) {
                            wrtri_m = getDetail_4(cyry_list);
                            wdti[3] = new WorkflowDetailTableInfo();
                            wdti[3].setWorkflowRequestTableRecords(wrtri_m);
                        }

                        //endregion
                        //region[明细表构造-参与人群赠品信息]
                        if (zp_list.size() > 0) {
                            wrtri_m = getDetail_5(zp_list);
                            log.info("赠品信息工作流信息填装！");
                            wdti[4] = new WorkflowDetailTableInfo();
                            wdti[4].setWorkflowRequestTableRecords(wrtri_m);
                        }

                        //endregion
                        //region[明细表构造-折扣信息]
                        if (szzk_list.size() > 0) {
                            log.info("折扣信息：");
                            wrtri_m = getDetail_6(szzk_list);
                            wdti[5] = new WorkflowDetailTableInfo();
                            wdti[5].setWorkflowRequestTableRecords(wrtri_m);
                        }
                        //endregion
                        wrInfo.setWorkflowDetailTableInfos(wdti);
                        wrInfo.setCreatorId(strUserid);

                        //endregion
                        WorkflowServiceImpl wfsi = new WorkflowServiceImpl();
                        String requestid = wfsi.doCreateWorkflowRequest(wrInfo, Integer.parseInt(strUserid));
                        log.info("【品牌】促销方案审批流程返回值==" + requestid);
                        if (!"".equals(requestid) && Integer.parseInt(requestid) > 0) {
                            log.info("【品牌】促销方案审批流程创建成功！");
                            jsonResult.put("status", "S");
                            jsonResult.put("message", "成功！");
                        } else {
                            jsonResult.put("status", "F");
                            jsonResult.put("message", "失败！");
                            log.info("【品牌】促销方案审批流程创建失败,失败原因：找不到下一节点审批人！");
                        }
                    }
                    //endregion
                }
                //endregion
            }
        } catch (Exception ex) {
            log.info("解析V8接口数据发生异常,异常信息：" + ex.toString());
            jsonResult.put("status", "F");
            jsonResult.put("message", "失败,异常信息:" + ex.toString());

        }
        return jsonResult;
    }

    /***
     * 更新主表
     * @param table_main 表名
     * @param strCxbh 促销编号
     * @param dataVo 主表封装的数据
     * @param strMainid 主键
     * @return
     */
    private Boolean updateTable_main(String table_main, String strCxbh, mainVo dataVo,String strMainid) {
        RecordSetTrans rsTrans;
        rsTrans=new RecordSetTrans();
        try{
            String strDep = MyCommonUtils.getDepByCode(dataVo.getTbr());//查询填报人所在部门
            String strUserid = MyCommonUtils.getUseridByCode(dataVo.getTbr());//获取填报人id
            String strYzxs="Y".equals(dataVo.getYzxs())?"1":"0";//原值销售
            String strCyzdbz="Y".equals(dataVo.getCyzdbz())?"1":"0";
            String strQzcyzdz="Y".equals(dataVo.getQzcyzd())?"1":"0";
            String strGqbz="Y".equals(dataVo.getGqbz())?"1":"0";
            String strSfzhj="Y".equals(dataVo.getSfzhj())?"1":"0";
            String strZdcxsfqzszp="Y".equals(dataVo.getZdcxsfqzszp())?"1":"0";
            String strDjmj="Y".equals(dataVo.getDjmj())?"1":"0";
            String strCsjl="";//城市经理
            if(!"".equals(dataVo.getLcbh())){
                strCsjl=getCsjl(dataVo.getLcbh());
            }
            String strTbDate = dataVo.getTbsj();
            if (strTbDate.length() > 10) {
                strTbDate = strTbDate.substring(0, 10);
            }
            String strCxjsrq = dataVo.getCxjsrq();
            if (strCxjsrq.length() > 10) {
                strCxjsrq = strCxjsrq.substring(0, 10);
            }
            String strPp=getPP(dataVo.getLcbh());//品牌
            String strDqjl=getInfos(dataVo.getLcbh(),"dqjl");//大区经理
            String strHpry=getInfos(dataVo.getLcbh(),"hpry");//货品人员
            String strCwjh=getInfos(dataVo.getLcbh(),"cwjh");//财务稽核
            String strQqid=getInfos(dataVo.getLcbh(),"qqid");//请求id
            String strUpdate="update "+table_main+" set tbr='"+strUserid+"',tbsj='"+strTbDate+"',tbbm='"+strDep+"',lxdh='"+dataVo.getLxdh()+"'" +
                    ",cxfasm='"+dataVo.getCxfasm()+"',cxfaxxsm='"+dataVo.getCxfaxxsm()+"',cxyy='"+dataVo.getCxyy()+"',yxsx='"+dataVo.getYxsx()+"',cxllzk='"+dataVo.getCxllzk()+"'" +
                    ",cxqsrq='"+dataVo.getCxqsrq()+"',cxjsrq='"+strCxjsrq+"',fqjey='"+dataVo.getFqjey()+"',mjjey='"+dataVo.getMjjey()+"',tjbz='"+dataVo.getTjbz()+"',spbz='"+dataVo.getSpbz()+"'" +
                    ",hdlx='"+dataVo.getHdlx()+"',yzktj='"+dataVo.getYzktj()+"',nsltj='"+dataVo.getNsltj()+"',xjetj='"+dataVo.getXjetj()+"',pxtj='"+dataVo.getPxtj()+"',cyzdbz='"+strCyzdbz+"',qzcyzd='"+strQzcyzdz+"'" +
                    ",gqbz='"+strGqbz+"',sfzhj='"+strSfzhj+"',zdcxsfqzszp='"+strZdcxsfqzszp+"',djmj='"+strDjmj+"',cxyycode='"+dataVo.getCxyyCode()+"',hdlxcode='"+dataVo.getHdlxCode()+"'" +
                    ",bz='"+dataVo.getBz()+"',gh='"+dataVo.getTbr()+"',pp='"+strPp+"',dqjl='"+strDqjl+"',hpry='"+strHpry+"',cwjh='"+strCwjh+"',csjl='"+strCsjl+"',cxfasqlc='"+strQqid+"',yzxs='"+strYzxs+"',sfztyzk='"+dataVo.getSfztyzk()+"' where id='"+strMainid+"'";
            log.info("更新主表语句："+strUpdate);
            rsTrans.execute(strUpdate);
            rsTrans.commit();
            log.info("更新主表数据成功！");
        }catch (Exception ex){
            ex.printStackTrace();
            log.info("更新主表发生异常,异常信息："+ex.toString());
            rsTrans.rollback();
            return  false;
        }
        return true;
    }

    /***
     * 更新参与店面信息-流程明细表
     * @param table_main 主表表名
     * @param strMainid 主表主键
     * @param strCxbh 促销编号
     * @param list 参与店面信息集合
     * @return
     */
    private Boolean updateTable_dt1(String table_main,String strMainid, String strCxbh, List<shopEntity> list) {
        log.info("更新表1-店面信息--");
        Boolean result=true;
        RecordSetTrans rsTrans_dt1;
            String strDelSql="delete "+table_main+"_dt1 where mainid="+strMainid;
            log.info("清除明细表1的数据Sql："+strDelSql);
            RecordSet rs_del=new RecordSet();
            rs_del.execute(strDelSql);
            for (shopEntity shopEntity : list) {
                //店面代码
                String strDmdm=shopEntity.getDmdm();
                //店面名称
                String strDmmc=shopEntity.getDmmc();
                //起始日期
                String strQsrq=shopEntity.getQsrq();
                if(strQsrq.length()>10){
                    strQsrq=strQsrq.substring(0,10);
                }
                //截止日期
                String strJzrq=shopEntity.getJzrq();
                if(strJzrq.length()>10){
                    strJzrq=strJzrq.substring(0,10);
                }
                //扣点
                String strKd=shopEntity.getKd();
                //合同扣点
                String strHtkd=shopEntity.getHtkd();
                rsTrans_dt1=new RecordSetTrans();
                try {
                    String strInsertSql = "insert into " + table_main + "_dt1 (mainid,dmdm,dmmc,qsrq,jzrq,kd,htkd) values " +
                            "('" + strMainid + "','" + strDmdm + "','" + strDmmc + "','" + strQsrq + "','" + strJzrq + "','" + strKd + "','" + strHtkd + "')";
                    log.info("插入数据到明细表1的sql语句：" + strInsertSql);
                    rsTrans_dt1.executeQuery(strInsertSql);
                    rsTrans_dt1.commit();
                }catch (Exception ex){
                    ex.printStackTrace();
                    log.info("更新明细表1发生异常,异常信息："+ex.toString());
                    rsTrans_dt1.rollback();
                    result=false;
                    break;
                }
            }
        return result;
    }

    /***
     * 构造参与店面信息-流程明细表
     * @param list
     * @return
     */
    public WorkflowRequestTableRecord[] getDetail_1(List<shopEntity> list) {
        log.info("店面信息：" + list.toString());
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String strDate = df.format(new Date());//日期
        //region[参与店面信息]
        WorkflowRequestTableRecord[] wrtri = new WorkflowRequestTableRecord[list.size()];
        WorkflowRequestTableField[] wrti;
        int i = 0;
        for (shopEntity shopEntity : list) {
            wrti = new WorkflowRequestTableField[6];
            //店面代码
            wrti[0] = new WorkflowRequestTableField();
            wrti[0].setFieldName("dmdm");
            wrti[0].setFieldValue(shopEntity.getDmdm());
            wrti[0].setView(true);
            wrti[0].setEdit(true);
            //店面名称
            wrti[1] = new WorkflowRequestTableField();
            wrti[1].setFieldName("dmmc");
            wrti[1].setFieldValue(shopEntity.getDmmc());
            wrti[1].setView(true);
            wrti[1].setEdit(true);
            //起始日期
            String strQsrq=shopEntity.getQsrq();
            if(strQsrq.length()>10){
                strQsrq=strQsrq.substring(0,10);
            }
            wrti[2] = new WorkflowRequestTableField();
            wrti[2].setFieldName("qsrq");
            wrti[2].setFieldValue(strQsrq);
            wrti[2].setView(true);
            wrti[2].setEdit(true);
            //截止日期
            String strJzrq=shopEntity.getJzrq();
            if(strJzrq.length()>10){
                strJzrq=strJzrq.substring(0,10);
            }
            wrti[3] = new WorkflowRequestTableField();
            wrti[3].setFieldName("jzrq");
            wrti[3].setFieldValue(strJzrq);
            wrti[3].setView(true);
            wrti[3].setEdit(true);
            //扣点
            wrti[4] = new WorkflowRequestTableField();
            wrti[4].setFieldName("kd");
            wrti[4].setFieldValue(shopEntity.getKd());
            wrti[4].setView(true);
            wrti[4].setEdit(true);
            //合同扣点
            wrti[5] = new WorkflowRequestTableField();
            wrti[5].setFieldName("htkd");
            wrti[5].setFieldValue(shopEntity.getHtkd());
            wrti[5].setView(true);
            wrti[5].setEdit(true);
            wrtri[i] = new WorkflowRequestTableRecord();
            wrtri[i].setWorkflowRequestTableFields(wrti);
            i++;
        }

        //endregion
        return wrtri;
    }

    /***
     * 更新参与店面信息-流程明细表
     * @param table_main 主表表名
     * @param strMainid 主表主键
     * @param strCxbh 促销编号
     * @param list 参与商品信息集合
     * @return
     */
    private Boolean updateTable_dt2(String table_main,String strMainid, String strCxbh, List<cxbEntity> list) {
        log.info("更新表2-参与商品信息--");
        Boolean result=true;
        RecordSetTrans rsTrans_dt2;
        String strDelSql="delete "+table_main+"_dt2 where mainid="+strMainid;
        log.info("清除明细表2的数据Sql："+strDelSql);
        RecordSet rs_del=new RecordSet();
        rs_del.execute(strDelSql);
        for (cxbEntity cxbEntity : list) {
            //促销方案包代码
            String strCxfabdm=cxbEntity.getCxfabdm();
            //促销方案包名称
            String strCxfabmc=cxbEntity.getCxfabmc();
            //促销方案包折扣
            String strCxfabzk=cxbEntity.getCxfabzk();
            //促销方案包类型
            String strCxblx=cxbEntity.getCxblx();
            rsTrans_dt2=new RecordSetTrans();
            try {
                String strInsertSql = "insert into " + table_main + "_dt2 (mainid,cxfabdm,cxfabmc,cxfabzk,cxblx) values " +
                        "('" + strMainid + "','" + strCxfabdm + "','" + strCxfabmc + "','" + strCxfabzk + "','" + strCxblx + "')";
                log.info("插入数据到明细表2的sql语句：" + strInsertSql);
                rsTrans_dt2.executeQuery(strInsertSql);
                rsTrans_dt2.commit();
            }catch (Exception ex){
                ex.printStackTrace();
                log.info("更新明细表2发生异常,异常信息："+ex.toString());
                rsTrans_dt2.rollback();
                result=false;
                break;
            }
        }
        return result;
    }

    /***
     * 构造参与商品信息-流程明细表
     * @param list
     * @return
     */
    public WorkflowRequestTableRecord[] getDetail_2(List<cxbEntity> list) {
        //region[参与商品/促销包信息]
        log.info("参与商品信息：" + list.toString());
        WorkflowRequestTableRecord[] wrtri = new WorkflowRequestTableRecord[list.size()];
        WorkflowRequestTableField[] wrti;
        for (int i = 0; i < list.size(); i++) {
            try {
                wrti = new WorkflowRequestTableField[4];
                //促销方案包代码
                wrti[0] = new WorkflowRequestTableField();
                wrti[0].setFieldName("cxfabdm");
                wrti[0].setFieldValue(list.get(i).getCxfabdm());
                wrti[0].setView(true);
                wrti[0].setEdit(true);
                //促销方案包名称
                wrti[1] = new WorkflowRequestTableField();
                wrti[1].setFieldName("cxfabmc");
                wrti[1].setFieldValue(list.get(i).getCxfabmc());
                wrti[1].setView(true);
                wrti[1].setEdit(true);
                //促销方案包折扣
                wrti[2] = new WorkflowRequestTableField();
                wrti[2].setFieldName("cxfabzk");
                wrti[2].setFieldValue(list.get(i).getCxfabzk());
                wrti[2].setView(true);
                wrti[2].setEdit(true);
                //促销方案包类型
                wrti[3] = new WorkflowRequestTableField();
                wrti[3].setFieldName("cxblx");
                wrti[3].setFieldValue(list.get(i).getCxblx());
                wrti[3].setView(true);
                wrti[3].setEdit(true);
                wrtri[i] = new WorkflowRequestTableRecord();
                wrtri[i].setWorkflowRequestTableFields(wrti);
            } catch (Exception ex) {
                log.info("封装商品信息-明细表数据出现异常,异常信息：" + ex.toString());
            }
        }
        //endregion
        return wrtri;
    }

    /***
     * 更新参与商品方案-流程明细表
     * @param table_main 主表表名
     * @param strMainid 主表主键
     * @param strCxbh 促销编号
     * @param list 参与商品方案集合
     * @return
     */
    private Boolean updateTable_dt3(String table_main,String strMainid, String strCxbh, List<zhcxEntity> list) {
        log.info("更新表3-参与商品方案--");
        Boolean result=true;
        RecordSetTrans rsTrans_dt3;
        String strDelSql="delete "+table_main+"_dt3 where mainid="+strMainid;
        log.info("清除明细表3的数据Sql："+strDelSql);
        RecordSet rs_del=new RecordSet();
        rs_del.execute(strDelSql);
        for (int i = 0; i < list.size(); i++) {
            try {
                List<cxspEntity> cxsp = list.get(i).getCxsp();
                for (int j = 0; j < cxsp.size(); j++) {
                    //折扣
                    String strZk=list.get(i).getZk();
                    //单价、组合方案总金额
                    String strjzhfazje=list.get(i).getDjzhfazje();
                    //换购积分
                    String strHgjf=list.get(i).getHgjf();
                    //积分等价金额
                    String strJfdjje=list.get(i).getJfdjje();
                    //方案
                    String strFa=list.get(i).getFa();
                    //款式
                    String strKs=cxsp.get(j).getKs();
                    //款号
                    String strKh=cxsp.get(j).getKh();
                    //品名
                    String strPm=cxsp.get(j).getPm();
                    //零售价
                    String strLsj=cxsp.get(j).getLsj();
                    rsTrans_dt3=new RecordSetTrans();
                    try {
                        String strInsertSql = "insert into " + table_main + "_dt3 (mainid,zk,djzhfazje,hgjf,jfdjje,fa,ks,kh,pm,lsj) values " +
                                "('" + strMainid + "','" + strZk + "','" + strjzhfazje + "','" + strHgjf + "','" + strJfdjje + "','" + strFa + "','" + strKs + "','" + strKh + "','" + strPm + "','" + strLsj + "')";
                        log.info("插入数据到明细表2的sql语句：" + strInsertSql);
                        rsTrans_dt3.executeQuery(strInsertSql);
                        rsTrans_dt3.commit();
                    }catch (Exception ex){
                        ex.printStackTrace();
                        log.info("更新明细表2发生异常,异常信息："+ex.toString());
                        rsTrans_dt3.rollback();
                        result=false;
                        break;
                    }
                }

            } catch (Exception ex) {
                log.info("封装商品方案-明细表数据出现异常,异常信息：" + ex.toString());
            }


        }
        return result;
    }

    /***
     * 构造参与商品方案-流程明细表
     * @param list
     * @return
     */
    public WorkflowRequestTableRecord[] getDetail_3(List<zhcxEntity> list) {
        //region[参与商品方案]
        log.info("参与商品方案：" + list.toString());
        Integer length=0;
        for (int i=0; i<list.size();i++){
            length+=list.get(i).getCxsp().size();
        }
        log.info("长度："+length);
        WorkflowRequestTableRecord[] wrtri = new WorkflowRequestTableRecord[length];
        WorkflowRequestTableField[] wrti;
        int index=0;
        for (int i = 0; i < list.size(); i++) {
            try {
                List<cxspEntity> cxsp = list.get(i).getCxsp();
                for (int j = 0; j < cxsp.size(); j++) {
                    wrti = new WorkflowRequestTableField[9];
                    //折扣
                    wrti[0] = new WorkflowRequestTableField();
                    wrti[0].setFieldName("zk");
                    wrti[0].setFieldValue(list.get(i).getZk());
                    wrti[0].setView(true);
                    wrti[0].setEdit(true);
                    //单价、组合方案总金额
                    wrti[1] = new WorkflowRequestTableField();
                    wrti[1].setFieldName("djzhfazje");
                    wrti[1].setFieldValue(list.get(i).getDjzhfazje());
                    wrti[1].setView(true);
                    wrti[1].setEdit(true);
                    //换购积分
                    wrti[2] = new WorkflowRequestTableField();
                    wrti[2].setFieldName("hgjf");
                    wrti[2].setFieldValue(list.get(i).getHgjf());
                    wrti[2].setView(true);
                    wrti[2].setEdit(true);
                    //积分等价金额
                    wrti[3] = new WorkflowRequestTableField();
                    wrti[3].setFieldName("jfdjje");
                    wrti[3].setFieldValue(list.get(i).getJfdjje());
                    wrti[3].setView(true);
                    wrti[3].setEdit(true);
                    //方案
                    wrti[4] = new WorkflowRequestTableField();
                    wrti[4].setFieldName("fa");
                    wrti[4].setFieldValue(list.get(i).getFa());
                    wrti[4].setView(true);
                    wrti[4].setEdit(true);
                    //款式
                    wrti[5] = new WorkflowRequestTableField();
                    wrti[5].setFieldName("ks");
                    wrti[5].setFieldValue(cxsp.get(j).getKs());
                    wrti[5].setView(true);
                    wrti[5].setEdit(true);
                    //款号
                    wrti[6] = new WorkflowRequestTableField();
                    wrti[6].setFieldName("kh");
                    wrti[6].setFieldValue(cxsp.get(j).getKh());
                    wrti[6].setView(true);
                    wrti[6].setEdit(true);
                    //品名
                    wrti[7] = new WorkflowRequestTableField();
                    wrti[7].setFieldName("pm");
                    wrti[7].setFieldValue(cxsp.get(j).getPm());
                    wrti[7].setView(true);
                    wrti[7].setEdit(true);
                    //零售价
                    wrti[8] = new WorkflowRequestTableField();
                    wrti[8].setFieldName("lsj");
                    wrti[8].setFieldValue(cxsp.get(j).getLsj());
                    wrti[8].setView(true);
                    wrti[8].setEdit(true);
                    log.info("零售价："+cxsp.get(j).getLsj());
                    wrtri[index] = new WorkflowRequestTableRecord();
                    wrtri[index].setWorkflowRequestTableFields(wrti);
                    index++;
                }

            } catch (Exception ex) {
                log.info("封装商品方案-明细表数据出现异常,异常信息：" + ex.toString());
            }


        }
        //endregion
        return wrtri;
    }

    /***
     * 更新参与人群信息-流程明细表
     * @param table_main 主表表名
     * @param strMainid 主表主键
     * @param strCxbh 促销编号
     * @param list 参与人群信息集合
     * @return
     */
    private Boolean updateTable_dt4(String table_main,String strMainid, String strCxbh, List<cyryEntity> list) {
        log.info("更新表4-参与商品方案--");
        Boolean result=true;
        RecordSetTrans rsTrans_dt4;
        String strDelSql="delete "+table_main+"_dt4 where mainid="+strMainid;
        log.info("清除明细表4的数据Sql："+strDelSql);
        RecordSet rs_del=new RecordSet();
        rs_del.execute(strDelSql);
        for (int i = 0; i < list.size(); i++) {
                //会员类型编号
                String strHylxbh=list.get(i).getHylxbh();
                //会员类型名称
                String strHylxmc=list.get(i).getHylxmc();
                //积分倍率
                String strJfbl=list.get(i).getJfbl();
                rsTrans_dt4=new RecordSetTrans();
                try {
                    String strInsertSql = "insert into " + table_main + "_dt4 (mainid,hylxbh,hylxmc,jfbl) values " +
                            "('" + strMainid + "','" + strHylxbh + "','" + strHylxmc + "','" + strJfbl + "')";
                    log.info("插入数据到明细表4的sql语句：" + strInsertSql);
                    rsTrans_dt4.executeQuery(strInsertSql);
                    rsTrans_dt4.commit();
                }catch (Exception ex){
                    ex.printStackTrace();
                    log.info("更新明细表4发生异常,异常信息："+ex.toString());
                    rsTrans_dt4.rollback();
                    result=false;
                    break;
                }
        }
        return result;
    }

    /***
     * 构造参与人群信息-流程明细表
     * @param list
     * @return
     */
    public WorkflowRequestTableRecord[] getDetail_4(List<cyryEntity> list) {
        //region[参与人群信息]
        log.info("参与人群信息：" + list.toString());
        WorkflowRequestTableRecord[] wrtri = new WorkflowRequestTableRecord[list.size()];
        WorkflowRequestTableField[] wrti;
        for (int i = 0; i < list.size(); i++) {
            try {
                wrti = new WorkflowRequestTableField[3];
                //会员类型编号
                wrti[0] = new WorkflowRequestTableField();
                wrti[0].setFieldName("hylxbh");
                wrti[0].setFieldValue(list.get(i).getHylxbh());
                wrti[0].setView(true);
                wrti[0].setEdit(true);
                //会员类型名称
                wrti[1] = new WorkflowRequestTableField();
                wrti[1].setFieldName("hylxmc");
                wrti[1].setFieldValue(list.get(i).getHylxmc());
                wrti[1].setView(true);
                wrti[1].setEdit(true);
                //积分倍率
                wrti[2] = new WorkflowRequestTableField();
                wrti[2].setFieldName("jfbl");
                wrti[2].setFieldValue(list.get(i).getJfbl());
                wrti[2].setView(true);
                wrti[2].setEdit(true);
                wrtri[i] = new WorkflowRequestTableRecord();
                wrtri[i].setWorkflowRequestTableFields(wrti);
            } catch (Exception ex) {
                log.info("封装人群信息-明细表数据出现异常,异常信息：" + ex.toString());
            }


        }
        //endregion
        return wrtri;
    }

    /***
     * 更新参与人群信息-流程明细表
     * @param table_main 主表表名
     * @param strMainid 主表主键
     * @param strCxbh 促销编号
     * @param list 参与人群信息集合
     * @return
     */
    private Boolean updateTable_dt5(String table_main,String strMainid, String strCxbh, List<zpEntity> list) {
        log.info("更新表5-参与商品方案--");
        Boolean result=true;
        RecordSetTrans rsTrans_dt5;
        String strDelSql="delete "+table_main+"_dt5 where mainid="+strMainid;
        log.info("清除明细表5的数据Sql："+strDelSql);
        RecordSet rs_del=new RecordSet();
        rs_del.execute(strDelSql);
        for (int i = 0; i < list.size(); i++) {
            //会员类型名称
            String strHylxmc=list.get(i).getHylxmc();
            //商品款色（到SKU级）
            String strSpks=list.get(i).getSpks();
            //品名
            String strPm=list.get(i).getPm();
            //零售价
            String strLsj=list.get(i).getLsj();
            //换购价
            String strHgj=list.get(i).getHgj();
            //数量
            String strSl=list.get(i).getSl();
            //选择标志
            String strXzbz=list.get(i).getXzbz().equals("Y")?"1":"0";
            //换购积分
            String strHgjf=list.get(i).getHgjf();
            //积分等价金额
            String strJf=list.get(i).getJfdjje();
            //兑换比例
            String strDhbl=list.get(i).getDhbl();
            //积分下限
            String strJfxx=list.get(i).getJfxx();
            //积分上限
            String strJfsx=list.get(i).getJfsx();
            //金额下限
            String strJexx=list.get(i).getJexx();
            rsTrans_dt5=new RecordSetTrans();
            try {
                String strInsertSql = "insert into " + table_main + "_dt5 (mainid,hylxmc,spks,pm,lsj,hgj,sl,xzbz,hgjf,jfdjje,dhbl,jfxx,jfsx,jexx) values " +
                        "('" + strMainid + "','" + strHylxmc + "','" + strSpks + "','" + strPm + "','" + strLsj + "','" + strHgj + "','" + strSl + "','" + strXzbz + "'" +
                        ",'" + strHgjf + "','" + strJf + "','" + strDhbl + "','" + strJfxx + "','" + strJfsx + "','" + strJexx + "')";
                log.info("插入数据到明细表5的sql语句：" + strInsertSql);
                rsTrans_dt5.executeQuery(strInsertSql);
                rsTrans_dt5.commit();
            }catch (Exception ex){
                ex.printStackTrace();
                log.info("更新明细表5发生异常,异常信息："+ex.toString());
                rsTrans_dt5.rollback();
                result=false;
                break;
            }
        }
        return result;
    }
    /***
     * 构造参与人群赠品信息-流程明细表
     * @param list
     * @return
     */
    public WorkflowRequestTableRecord[] getDetail_5(List<zpEntity> list) {
        //region[参与人群赠品信息]
        log.info("参与人群赠品信息：" + list.toString());
        WorkflowRequestTableRecord[] wrtri = new WorkflowRequestTableRecord[list.size()];
        WorkflowRequestTableField[] wrti;
        for (int i = 0; i < list.size(); i++) {
            try {
                wrti = new WorkflowRequestTableField[13];
                //参与类型名称
                wrti[0] = new WorkflowRequestTableField();
                wrti[0].setFieldName("hylxmc");
                wrti[0].setFieldValue(list.get(i).getHylxmc());
                wrti[0].setView(true);
                wrti[0].setEdit(true);
                //商品款色（到SKU级）
                wrti[1] = new WorkflowRequestTableField();
                wrti[1].setFieldName("spks");
                wrti[1].setFieldValue(list.get(i).getSpks());
                wrti[1].setView(true);
                wrti[1].setEdit(true);
                //品名
                wrti[2] = new WorkflowRequestTableField();
                wrti[2].setFieldName("pm");
                wrti[2].setFieldValue(list.get(i).getPm());
                wrti[2].setView(true);
                wrti[2].setEdit(true);

                //零售价
                wrti[3] = new WorkflowRequestTableField();
                wrti[3].setFieldName("lsj");
                String strLsj=list.get(i).getLsj();
                if(!strLsj.equals("")&&strLsj!=null) {
                    wrti[3].setFieldValue(strLsj);
                }
                wrti[3].setView(true);
                wrti[3].setEdit(true);
                //换购价
                wrti[4] = new WorkflowRequestTableField();
                wrti[4].setFieldName("hgj");
                String strHgj=list.get(i).getHgj();
                log.info("换购价："+strHgj);
                if(!strHgj.equals("")&&strHgj!=null) {
                    wrti[4].setFieldValue(strHgj);
                }
                wrti[4].setView(true);
                wrti[4].setEdit(true);
                //数量
                wrti[5] = new WorkflowRequestTableField();
                wrti[5].setFieldName("sl");
                String strSl=list.get(i).getSl();
                if(!strSl.equals("")&&strSl!=null) {
                    wrti[5].setFieldValue(strSl);
                }
                wrti[5].setView(true);
                wrti[5].setEdit(true);
                //选择标志
                wrti[6] = new WorkflowRequestTableField();
                wrti[6].setFieldName("xzbz");
                wrti[6].setFieldValue(list.get(i).getXzbz().equals("Y")?"1":"0");
                wrti[6].setView(true);
                wrti[6].setEdit(true);
                //换购积分
                wrti[7] = new WorkflowRequestTableField();
                wrti[7].setFieldName("hgjf");
                wrti[7].setFieldValue(list.get(i).getHgjf());
                wrti[7].setView(true);
                wrti[7].setEdit(true);
                //积分等价金额
                wrti[8] = new WorkflowRequestTableField();
                wrti[8].setFieldName("jfdjje");
                String strJf=list.get(i).getJfdjje();
                if(!strJf.equals("")&&strJf!=null) {
                    wrti[8].setFieldValue(strJf);
                }
                wrti[8].setView(true);
                wrti[8].setEdit(true);
                //兑换比例
                wrti[9] = new WorkflowRequestTableField();
                wrti[9].setFieldName("dhbl");
                wrti[9].setFieldValue(list.get(i).getDhbl());
                wrti[9].setView(true);
                wrti[9].setEdit(true);
                //积分下限
                wrti[10] = new WorkflowRequestTableField();
                wrti[10].setFieldName("jfxx");
                wrti[10].setFieldValue(list.get(i).getJfxx());
                wrti[10].setView(true);
                wrti[10].setEdit(true);
                //积分上限
                wrti[11] = new WorkflowRequestTableField();
                wrti[11].setFieldName("jfsx");
                wrti[11].setFieldValue(list.get(i).getJfsx());
                wrti[11].setView(true);
                wrti[11].setEdit(true);
                //金额下限
                wrti[12] = new WorkflowRequestTableField();
                wrti[12].setFieldName("jexx");
                wrti[12].setFieldValue(list.get(i).getJexx());
                wrti[12].setView(true);
                wrti[12].setEdit(true);
                log.info("赠品信息封装字段结束！");
                wrtri[i] = new WorkflowRequestTableRecord();
                wrtri[i].setWorkflowRequestTableFields(wrti);
            } catch (Exception ex) {
                log.info("封装人群赠品信息-明细表数据出现异常,异常信息：" + ex.toString());
            }


        }
        //endregion
        return wrtri;
    }

    /***
     * 更新设置折扣-流程明细表
     * @param table_main 主表表名
     * @param strMainid 主表主键
     * @param strCxbh 促销编号
     * @param list 设置折扣集合
     * @return
     */
    private Boolean updateTable_dt6(String table_main,String strMainid, String strCxbh, List<szzkEntity> list) {
        log.info("更新表6-设置折扣--");
        Boolean result=true;
        RecordSetTrans rsTrans_dt6;
        String strDelSql="delete "+table_main+"_dt6 where mainid="+strMainid;
        log.info("清除明细表6的数据Sql："+strDelSql);
        RecordSet rs_del=new RecordSet();
        rs_del.execute(strDelSql);
        for (int i = 0; i < list.size(); i++) {
            //名称
            String strMc=list.get(i).getMc();
            //折扣
            String strZk=list.get(i).getZk();
            rsTrans_dt6=new RecordSetTrans();
            try {
                String strInsertSql = "insert into " + table_main + "_dt6 (mainid,mc,zk) values " +
                        "('" + strMainid + "','" + strMc + "','" + strZk + "')";
                log.info("插入数据到明细表6的sql语句：" + strInsertSql);
                rsTrans_dt6.executeQuery(strInsertSql);
                rsTrans_dt6.commit();
            }catch (Exception ex){
                ex.printStackTrace();
                log.info("更新明细表6发生异常,异常信息："+ex.toString());
                rsTrans_dt6.rollback();
                result=false;
                break;
            }
        }
        return result;
    }

    /***
     * 构造设置折扣-流程明细表
     * @param list
     * @return
     */
    public WorkflowRequestTableRecord[] getDetail_6(List<szzkEntity> list) {
        //region[设置折扣信息]
        log.info("设置折扣：" + list.toString());
        WorkflowRequestTableRecord[] wrtri = new WorkflowRequestTableRecord[list.size()];
        WorkflowRequestTableField[] wrti;
        for (int i = 0; i < list.size(); i++) {
            try {
                wrti = new WorkflowRequestTableField[2];
                //名称
                wrti[0] = new WorkflowRequestTableField();
                wrti[0].setFieldName("mc");
                wrti[0].setFieldValue(list.get(i).getMc());
                wrti[0].setView(true);
                wrti[0].setEdit(true);
                //折扣
                wrti[1] = new WorkflowRequestTableField();
                wrti[1].setFieldName("zk");
                wrti[1].setFieldValue(list.get(i).getZk());
                wrti[1].setView(true);
                wrti[1].setEdit(true);
                wrtri[i] = new WorkflowRequestTableRecord();
                wrtri[i].setWorkflowRequestTableFields(wrti);
            } catch (Exception ex) {
                log.info("封装折扣信息-明细表数据出现异常,异常信息：" + ex.toString());
            }


        }
        //endregion
        return wrtri;
    }

    /***
     * 获取城市经理
     * @param lcbh
     * @return
     */
    public String getCsjl(String lcbh){
        String strCsjl="";
        String sql="SELECT csjl FROM uf_cxfntz WHERE bpmsqbh='"+lcbh+"'";
        RecordSet rs=new RecordSet();
        try{
        rs.execute(sql);
        while (rs.next()){
            strCsjl= Util.null2String(rs.getString("csjl"));
        }
        }catch (Exception ex){
            strCsjl="";
        }finally {
            return strCsjl;
        }

    }
    /***
     * 获取品牌
     * @param lcbh
     * @return
     */
    public String getPP(String lcbh){
        String strResult="";
        String sql="SELECT pp FROM uf_cxfntz WHERE bpmsqbh='"+lcbh+"'";
        RecordSet rs=new RecordSet();
        try{
            rs.execute(sql);
            while (rs.next()){
                strResult= Util.null2String(rs.getString("pp"));
            }
        }catch (Exception ex){
            strResult="";
        }finally {
            return strResult;
        }

    }
    /***
     * 判断流程编号是否存在
     * @param lcbh
     * @return
     */
    public Boolean isExists_lcbh(String lcbh){
        Boolean result=false;
        String sql="SELECT bpmsqbh FROM uf_cxfntz WHERE bpmsqbh='"+lcbh+"' AND ((zt=0 OR zt=3) OR SFKCFSY=0)";
        log.info("查询流程编号是否存在的sql:"+sql);
        RecordSet rs=new RecordSet();
        try{
            rs.execute(sql);
            while (rs.next()){
              result=true;
            }
        }catch (Exception ex){
            result=false;
        }finally {
            return result;
        }

    }
    /***
     * 获取大区经理，货品人员，财务稽核
     * @param lcbh
     * @param cType 类型
     * @return
     */
    public String getInfos(String lcbh,String cType){
        String strResult="";
        String sql="SELECT dqjl,hpry,cwjh,qqid FROM uf_cxfntz WHERE bpmsqbh='"+lcbh+"'";
        RecordSet rs=new RecordSet();
        try{
            rs.execute(sql);
            while (rs.next()){
              strResult= Util.null2String(rs.getString(cType));
            }
        }catch (Exception ex){
            strResult="";
        }finally {
            return strResult;
        }

    }
}
